using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class PostPhotoWithCtrl : UserControl
	{
		public delegate void AddContactClick(object sender, object object_0);
		public List<Contact> conList;
		private bool bIsTapFromChildren;
		private int showDelCount;
		public bool bHasInit;
		private Image addContactImg;
		private Grid addImgGrid;
		internal Grid LayoutRoot;
		internal ScrollViewer mScrollViewer;
		internal WrapPanel imgPanel;
		private bool _contentLoaded;
		public event PostPhotoWithCtrl.AddContactClick AddClick;
		private void InitAddImg()
		{
			this.addImgGrid = new Grid();
			this.addImgGrid.set_Width(108.0);
			this.addImgGrid.set_Height(108.0);
			this.addImgGrid.set_Background(R.theme.SNS_USERPAGEITEM_TAKEPHOTO_BK_BRUSH);
			this.addImgGrid.set_Margin(new Thickness(0.0, 2.0, 2.0, 0.0));
			this.addContactImg = new Image();
			this.addContactImg.set_Stretch(0);
			this.addContactImg.set_VerticalAlignment(1);
			this.addContactImg.set_HorizontalAlignment(1);
			this.addContactImg.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.sns_sendpic_addpeople_icon) as ImageSource);
			this.addContactImg.add_Tap(new EventHandler<GestureEventArgs>(this.addContactImg_Tap));
			this.addImgGrid.get_Children().Add(this.addContactImg);
		}
		private void addContactImg_Tap(object sender, GestureEventArgs e)
		{
			this.bIsTapFromChildren = true;
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is SnsPostPage)
			{
				SnsPostPage snsPostPage = rootPage as SnsPostPage;
				snsPostPage.conList = this.conList;
			}
			if (this.AddClick != null)
			{
				this.AddClick(this, e);
			}
		}
		public PostPhotoWithCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.PostPhotoWithCtrl_Loaded));
		}
		public void Init(List<Contact> mList)
		{
			if (this.bHasInit)
			{
				return;
			}
			this.conList = mList;
			this.InitAddImg();
			this.InitHeadImg();
			this.bHasInit = true;
		}
		public void AddDate(List<Contact> mList)
		{
			if (!this.bHasInit)
			{
				this.Init(mList);
				return;
			}
			for (int i = 0; i < mList.get_Count(); i++)
			{
				PostPhotoWithHeadImg postPhotoWithHeadImg = new PostPhotoWithHeadImg(mList.get_Item(i).strUsrName);
				this.imgPanel.get_Children().Insert(this.imgPanel.get_Children().get_Count() - 1, postPhotoWithHeadImg);
				postPhotoWithHeadImg.DelClick += new PostPhotoWithHeadImg.DelItemClick(this.withHeadImg_DelClick);
			}
		}
		private void InitHeadImg()
		{
			if (this.conList == null)
			{
				return;
			}
			for (int i = 0; i < this.conList.get_Count(); i++)
			{
				PostPhotoWithHeadImg postPhotoWithHeadImg = new PostPhotoWithHeadImg(this.conList.get_Item(i).strUsrName);
				this.imgPanel.get_Children().Add(postPhotoWithHeadImg);
				postPhotoWithHeadImg.DelClick += new PostPhotoWithHeadImg.DelItemClick(this.withHeadImg_DelClick);
			}
			this.imgPanel.get_Children().Add(this.addImgGrid);
			this.mScrollViewer.add_Tap(new EventHandler<GestureEventArgs>(this.mScrollViewer_Tap));
		}
		private void PostPhotoWithCtrl_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void mScrollViewer_Tap(object sender, GestureEventArgs e)
		{
			if (this.bIsTapFromChildren)
			{
				this.bIsTapFromChildren = false;
				return;
			}
			this.ResetState();
		}
		private void withHeadImg_DelClick(object sender, object object_0)
		{
			this.bIsTapFromChildren = true;
			PostPhotoWithHeadImg postPhotoWithHeadImg = sender as PostPhotoWithHeadImg;
			if (postPhotoWithHeadImg.bIsDelShown)
			{
				this.showDelCount++;
				return;
			}
			this.imgPanel.get_Children().Remove(postPhotoWithHeadImg);
			this.showDelCount--;
			if (this.showDelCount == 0)
			{
				this.ResetState();
			}
			string text = (string)object_0;
			for (int i = 0; i < this.conList.get_Count(); i++)
			{
				if (this.conList.get_Item(i).strUsrName == text)
				{
					this.conList.RemoveAt(i);
				}
			}
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is SnsPostPage)
			{
				SnsPostPage snsPostPage = rootPage as SnsPostPage;
				snsPostPage.conList = this.conList;
			}
		}
		public void ResetState()
		{
			if (this.imgPanel.get_Children().get_Count() == 0)
			{
				return;
			}
			if (this.imgPanel.get_Children().get_Item(this.imgPanel.get_Children().get_Count() - 1) is PostPhotoWithHeadImg)
			{
				this.imgPanel.get_Children().Add(this.addContactImg);
			}
			for (int i = 0; i < this.imgPanel.get_Children().get_Count() - 1; i++)
			{
				PostPhotoWithHeadImg postPhotoWithHeadImg = this.imgPanel.get_Children().get_Item(i) as PostPhotoWithHeadImg;
				postPhotoWithHeadImg.ResetState();
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/UploadAndPost/PostPhotoWithCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.mScrollViewer = (ScrollViewer)base.FindName("mScrollViewer");
			this.imgPanel = (WrapPanel)base.FindName("imgPanel");
		}
	}
}
